//
//  CQAccountTool.m
//  01-OC微博
//
//  Created by 陈乾 on 15/11/2.
//  Copyright © 2015年 陈乾. All rights reserved.
//

#import "CQAccountTool.h"
#import "CQAccount.h"


#define CQFilePath  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0] stringByAppendingPathComponent:@"account.plist"]

@implementation CQAccountTool

static CQAccount *_account;

+(void)saveAccount:(CQAccount *)account{
  
    [NSKeyedArchiver archiveRootObject:account toFile:CQFilePath];
    
}

+(CQAccount*)loadAccount
{
    if (_account == nil) {
        //才去沙盒中取
      _account = [NSKeyedUnarchiver unarchiveObjectWithFile:CQFilePath];
    }
    
    //判断账号是否过期
    if ([[NSDate date] compare:_account.expires_date] != NSOrderedAscending) {
        //来着 说明过期
        return nil;
    }
    
    return _account;
}


@end
